package com.onedec.attendance.utils;


import lombok.Data;

import java.util.List;

@Data
public class Result {
    /**
     * 执行是否成功
     */
    private boolean success;
    /**
     * 结果码
     * 0000  成功
     * 0100  数据库失败
     * 1000  失败
     */
    private String code;

    /**
     * 详细信息
     */
    private String message;

    private List list;

    /**
     * 返回数据
     */
    private Object obj;

    public Result() {
    }

    public Result(boolean success, String code, String message, Object data, List list) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.obj=data;
        this.list=list;
    }

    public static com.onedec.attendance.utils.Result success(){
        return success(null,null);
    }
    public static com.onedec.attendance.utils.Result success(Object data,List list){
        return new com.onedec.attendance.utils.Result(true,"0000","执行成功",data,list);
    }

    public static com.onedec.attendance.utils.Result fail(String message ){
        return new com.onedec.attendance.utils.Result(false,"1000",message,null,null);
    }

    public static com.onedec.attendance.utils.Result fail(String code, String message ){
        return new com.onedec.attendance.utils.Result(false,code,message,null,null);
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }


    @Override
    public String toString() {
        return "Result{" +
                "success=" + success +
                ", code='" + code + '\'' +
                ", message='" + message + '\'' +
                ", data=" + obj +
                '}';
    }
}